package com.maoxx.humanresourcemanage_service.controller;

import com.maoxx.humanresourcemanage_service.dto.ResponseDTO;
import com.maoxx.humanresourcemanage_service.entity.Menu;
import com.maoxx.humanresourcemanage_service.service.MenuService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @className: MenuController
 * @author: Maoxx
 * @date: 2024/11/11 13:35
 * @Version: 1.0
 * @description:
 */

@RestController
@RequestMapping("/menu")
public class MenuController {

    @Resource
    private MenuService menuService;


    @ApiOperation("新增菜单")
    @PostMapping
    public ResponseDTO add(@RequestBody Menu menu){
        return menuService.add(menu);
    }

    @ApiOperation("修改菜单")
    @PutMapping
    public ResponseDTO edit(@RequestBody Menu menu){
        return menuService.edit(menu);
    }


    @ApiOperation("分页条件查询")
    @GetMapping
    public ResponseDTO list(@RequestParam(defaultValue = "1") Integer current,
                            @RequestParam(defaultValue = "10") Integer size,
                            String name) {
        return menuService.list(current,size,name);
    }


    @ApiOperation("逻辑删除")
    @DeleteMapping("/{id}")
    public ResponseDTO deleteOne(@PathVariable("id") Integer id) {
        return menuService.deleteOne(id);
    }

    @ApiOperation("批量删除菜单")
    @DeleteMapping("/batch/{ids}")
    public ResponseDTO deleteBatch(@PathVariable List<Integer> ids) {
        return menuService.deleteBatch(ids);
    }



    @ApiOperation("获取员工的菜单")
    @GetMapping("/staff/{id}")
    public ResponseDTO getStaffMenu(@PathVariable("id") Integer id) {
        return menuService.getStaffMenu(id);
    }

    @ApiOperation("查询所有")
    @GetMapping("/all")
    public ResponseDTO findAll(){
        return this.menuService.findAll();
    }

    @ApiOperation("数据导出接口")
    @GetMapping("/export")
    public ResponseDTO export(HttpServletResponse response) throws IOException {
        return menuService.export(response);
    }

    @ApiOperation("数据导入接口")
    @PostMapping("/import")
    public ResponseDTO imp(MultipartFile file) throws IOException {
        return menuService.imp(file);
    }
}
